package com.fxkj.cloud.drms.domain.device.repository;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fxkj.cloud.dbs.common.constants.DeviceStatusEnum;
import lombok.Getter;

/**
 * <p>description: </p>
 * @author ww
 * @date 2025/4/10 17:19
 */
@Getter
public class ProductDeviceStatusChangeHistoryDetail {
    private final Long ts;
    private final Long count;
    private final DeviceStatusEnum status;
    private final String rate;

    public ProductDeviceStatusChangeHistoryDetail(Long ts, Long count, DeviceStatusEnum status, String rate) {
        this.ts = ts;
        this.count = count;
        this.status = status;
        this.rate = rate;
    }

    public static ProductDeviceStatusChangeHistoryDetail create(Long ts, Long count, Integer status, Long totalCount) {
        DeviceStatusEnum deviceStatusEnum = DeviceStatusEnum.of(status);
        return new ProductDeviceStatusChangeHistoryDetail(
                ts,
                count,
                deviceStatusEnum,
                null == totalCount || 0 >= totalCount ? "0" : String.format("%.2f", (double) count / totalCount * 100)
        );
    }
}
